package labox.innovation.log;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

import labox.innovation.gameserver.model.L2Skill;
import labox.innovation.gameserver.model.actor.L2Attackable;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.model.actor.L2Summon;
import labox.innovation.gameserver.model.actor.instance.FuzePcInstance;
import labox.innovation.gameserver.util.StringUtil;

public class DamageFormatter extends Formatter {
	private static final String CRLF = "\r\n";

	private SimpleDateFormat dateFmt = new SimpleDateFormat("yy.MM.dd H:mm:ss");

	@Override
	public String format(LogRecord record) {
		final Object[] params = record.getParameters();
		final StringBuilder output = StringUtil.startAppend(30 + record.getMessage().length() + (params == null ? 0 : params.length * 10), "[", dateFmt.format(new Date(record.getMillis())), "] '---': ", record.getMessage());
		for (Object p : params) {
			if (p == null)
				continue;

			if (p instanceof L2Character) {

				StringUtil.append(output, ((L2Character) p).getName(), "(", String.valueOf(((L2Character) p).getObjectId()), ") ");
				StringUtil.append(output, String.valueOf(((L2Character) p).getLevel()), " lvl");

				if (p instanceof L2Summon) {
					FuzePcInstance owner = ((L2Summon) p).getOwner();
					if (owner != null)
						StringUtil.append(output, " Owner:", owner.getName(), "(", String.valueOf(owner.getObjectId()), ")");
				}
			} else if (p instanceof L2Skill) {
				StringUtil.append(output, " with skill ", ((L2Skill) p).getName(), "(", String.valueOf(((L2Skill) p).getId()), ")");
			} else
				StringUtil.append(output, p.toString());
		}
		output.append(CRLF);
		return output.toString();
	}
}
